package com.example.statistics.ui.sales

import android.os.Bundle
import com.example.statistics.R
import com.example.statistics.bean.MarketSales
import com.example.statistics.common.BaseLoadingListActivity
import com.example.statistics.ex.goTimeFormat
import com.example.statistics.ex.httpGet
import com.example.statistics.ex.messageDialog
import com.example.statistics.net.UrlConfig
import com.example.statistics.utils.Constants
import com.example.statistics.utils.activityForResult
import com.jhj.slimadapter.SlimAdapter
import com.jhj.slimadapter.holder.ViewInjector
import com.example.statistics.ex.onActionLongClicked

class MarketSalesListActivity : BaseLoadingListActivity<MarketSales>() {
    override val title: String
        get() = "商品流向"
    override val url: String
        get() = UrlConfig.PRODUCT_FLOW_LIST
    override val itemLayoutRes: Int
        get() = R.layout.list_item_shipment
    override val inputSearch: Boolean
        get() = true

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        topBarRightImage {
            activityForResult<MarketSalesEditActivity>() {
                refresh()
            }
        }
    }

    override fun itemViewConvert(adapter: SlimAdapter, injector: ViewInjector, bean: MarketSales, position: Int) {
        injector.text(R.id.tv_title, bean.factoryNo + bean.productName + bean.number + "件")
                .text(R.id.tv_area, bean.salesArea)
                .text(R.id.tv_time, bean.date?.goTimeFormat("yyyy-MM-dd"))
                .text(R.id.tv_customer, bean.customer)
                .clicked {
                    activityForResult<MarketSalesEditActivity>(Constants.DATA to bean) {
                        refresh()
                    }
                }
                .onActionLongClicked(
                        "删除" to {
                            messageDialog(msg = "是否删除${bean.salesArea + bean.factoryNo + bean.productName + bean.number + "件"}") { _, _ ->
                                httpGet<Any>(UrlConfig.MARKET_SALES_DELETE, config = {
                                    listParams = listOf("id" to bean.id)
                                }) {
                                    refresh()
                                }
                            }
                        }
                )

    }


}